
/* default ranking weights | use cookies if exist */

var weights = new Array();
weights['present'] = 20;
weights['participation'] = 60;
weights['initiatives'] = 40;
weights['initiatedParticipation'] = 40;
weights['interuption'] = 20;
weights['wordCount'] = 20;
var checkBox = new Array();
checkBox['chair'] = 'false';
checkBox['government'] = 'true';
checkBox['mp'] = 'true';



for (key in weights) {
    var tmp = getCookie("activity_weight_" + key);
    if (tmp != null) weights[key] = tmp;
}
for (key in checkBox) {
    var tmp = getCookie("activity_checkBox_" + key);
    if (tmp != null) checkBox[key] = tmp;
}

/* get and set cookies */
// bron: http://www.w3schools.com/js/js_cookies.asp

function setCookie(c_name,value,exdays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++) {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name) {
            return unescape(y);
        }
    }
}

// Create configuration tools
function activity_createConfigurationTools() {

    activity_createSlider("present");
    activity_createSlider("participation");
    activity_createSlider("initiatives");
    activity_createSlider("interuption");
    activity_createSlider("wordCount");
    activity_createSlider("initiatedParticipation");

    if (checkBox['mp'] == 'true') $(".includeMPField").attr('checked', 'checked');
    if (checkBox['chair'] == 'true') $(".includeChairField").attr('checked', 'checked');
    if (checkBox['government'] == 'true') $(".includeGovernmentField").attr('checked', 'checked');

    $(".includeMPField").change(function() {
        if (checkBox['mp'] == 'true') checkBox['mp'] = 'false'; else checkBox['mp'] = 'true';
        setCookie("activity_checkBox_mp", checkBox['mp'], null);
        activity_run();});
    $(".includeChairField").change(function() {
        if (checkBox['chair'] == 'true') checkBox['chair'] = 'false'; else checkBox['chair'] = 'true';
        setCookie("activity_checkBox_chair", checkBox['chair'], null);
        activity_run();});
    $(".includeGovernmentField").change(function() {
        if (checkBox['government'] == 'true') checkBox['government'] = 'false'; else checkBox['government'] = 'true';
        setCookie("activity_checkBox_government", checkBox['government'], null);
        activity_run();});
}

// create sliders
function activity_createSlider(name) {
	$( "#"+name+"Slider" ).slider({
		value: weights[name],
		orientation: "horizontal",
		range: "min",
		min: 0,
		max: 100,
		animate: true,
		slide: function( event, ui ) {
			$( "#"+name+"Amount" ).val( ui.value + "%" );
			//weights[name] = ui.value;
			//setCookie();
		},
		stop: function( event, ui ) {
		    weights[name] = ui.value;
		    setCookie("activity_weight_" + name, ui.value, null);
		    activity_run();
		}
	});
	$( "#"+name+"Amount" ).val($( "#"+name+"Slider" ).slider( "value" ) + "%");
}

/* Set box positioning */
function activity_load_boxPositioning() {
    var valueTop = $("#manWomenValueChartBox").position().top;
    var rankingTop = $("#manWomenRankingChartBox").position().top;
    if (valueTop > rankingTop)
        $("#rankingChartColumn").css({"padding-top" : valueTop - ( $(".containerBox").position().top)});
}

/* Register functions + run */
// possible:
// - createConfigurationTools
// - update [deprecated]

var updateFunction;

function activity_setUpdateFunction(func) {
    updateFunction = func;
}

function activity_run() {

    // get content
    $.ajax({
        url: "activity_list.xql"
        + "?present="+(weights['present'] / 100)+"&initiator="+(weights['initiatives'] / 100)
        + "&participation="+(weights['participation'] / 100)
        + "&interuption="+(weights['interuption'] / 100)
        + "&wordCount="+(weights['wordCount'] / 100)
        + "&initiatedParticipation="+(weights['initiatedParticipation'] / 100)
        + "&includeChair="+checkBox['chair']
        + "&includeGovernment="+checkBox['government']
        + "&includeMP="+checkBox['mp'],
        dataType: "xml",
        success: function(xml) {
            updateFunction(xml);
        }
    });

}

/* Individual charts */

function activity_loadPartyChart(xml, id, width, height) {
    activity_drawValueChart(xml, "#ppartyStats", activity_politicalPartyColors(), "#"+id, "Politieke partijen", null, width, height);
}

function activity_loadManWomenChart(xml, id, width, height) {
    activity_drawValueChart(xml, "#sexStats", activity_sexColors(), "#"+id, "Mannen vs Vrouwen", activity_sexLabels(), width, height);
}

function activity_loadMayorChart(xml, id, width, height) {
    activity_drawValueChart(xml, "#mayorStats", activity_mayorColors(), "#"+id, "Burgemeesters vs Niet-burgemeesters", activity_mayorLabels(), width, height);
}

function activity_loadRankingList(xml, id, showActivity) {
    activity_fillRankingList(xml, id, showActivity);
}

function activity_loadTopList(xml, rankingId, mostId, leastId) {   
    activity_fillTopList(xml, rankingId, mostId, leastId);
}

function activity_loadPartyRankingChart(xml, id, width, height) {
    activity_drawRankingChart(xml, "#ppartyStats", activity_politicalPartyColors(), "#"+id, "Politieke partijen", null, width, height);
}

function activity_loadManWomenRankingChart(xml, id, width, height) {
    activity_drawRankingChart(xml, "#sexStats", activity_sexColors(), "#"+id, "Mannen vs Vrouwen", activity_sexLabels(), width, height);
}

function activity_loadMayorRankingChart(xml, id, width, height) {
    activity_drawRankingChart(xml, "#mayorStats", activity_mayorColors(), "#"+id, "Burgemeesters vs Niet-burgemeesters", activity_mayorLabels(), width, height);
}

function activity_loadQuartilePartyPieChart(xml, id, part, title) {

    list = new Array();
    colorList = new Array();
    ppartyColors = activity_politicalPartyColors();
    list[0] = ['Partij', 'Aantal personen'];
    var j = 1;
    $(xml).find("#ppartyStats item").each(function() {
        var partyName = $(this).find("name").text()
        list[j] = [partyName, parseInt($(this).find(part).text())];
    colorList[j-1] = '#'+ppartyColors[partyName];
    ++j;
    });
    drawPartChart(id, list, title, colorList);

}


function activity_loadQuartileManWomenPieChart(xml, chartId, part, title) {

    var list = [['Geslacht', 'Aantal personen'],
                ['Mannen', null],
                ['Vrouwen', null]];

    $(xml).find("#sexStats item").each(function() {
        if($(this).find("name").text() == 'M')
            list[1][1] = parseInt($(this).find(part).text());
        else if ($(this).find("name").text() == 'F')
            list[2][1] = parseInt($(this).find(part).text());
    });

    var data = google.visualization.arrayToDataTable(list);

    var options = {
      title: title,
      is3D: true,
      colors: ['#000080', '#800000']
    };

    var chart = new google.visualization.PieChart(document.getElementById(chartId));
    chart.draw(data, options)
}

function activity_loadQuartileMayorPieChart(xml, chartId, part, title) {

    var list = [['(Niet)Burgemeester', 'Aantal personen'],
                ['Niet-burgemeesters', null],
                ['Burgemeesters', null]];

    $(xml).find("#mayorStats item").each(function() {
        if($(this).find("name").text() == 'TRUE')
            list[2][1] = parseInt($(this).find(part).text());
        else if ($(this).find("name").text() == 'FALSE')
            list[1][1] = parseInt($(this).find(part).text());
    });

    var data = google.visualization.arrayToDataTable(list);

    var options = {
      title: title,
      is3D: true,
      colors: ['#000080', '#800000']
    };

    var chart = new google.visualization.PieChart(document.getElementById(chartId));
    chart.draw(data, options)
}

function activity_loadIndividualInfoChart(xml, id, individualId) {
    var indiLi = $(xml).find("li[ref='"+individualId+"']");
    var role = $(indiLi).find("role").text();
    var party = $(indiLi).find("party").text();
    var manWomenName = $(indiLi).find("sex").text();
    var mayorName = $(indiLi).find("mayor").text();
    $("#"+id).empty().append(
            '<h1>' + $(indiLi).find("name").text() + '</h1>' +
            '<strong>' + (role=='mpRole'? 'Volksvertegenwoordiger' : (role=='governmentRole'? 'Regeeringslid' : 'Voorzitter'))+ '</strong> | ' +
            '<strong>' + party + '</strong> | ' +
            '<strong>' + (manWomenName == 'M'? 'Man' : 'Vrouw') + '</strong> | ' +
            '<strong>' + (mayorName == 'FALSE'? 'Niet-burgemeester' : 'Burgemeester') + '</strong>'
    );
}

function activity_loadIndividualRankingField(xml, id, individualId, functionRef) {
    var ranking = $(xml).find('root li[ref=\''+individualId+'\']').attr('ranking');
    $('#'+id).html('Ranking: #'+ranking);

    if (functionRef)
        functionRef(xml);
}

function activity_loadIndividualActivityChart(xml, id, individualId) {
    var indiLi = $(xml).find("li[ref='"+individualId+"']");
    var indiRanking = Math.round(parseFloat($(indiLi).attr("ranking")));
    var indiName = $(indiLi).find("name").text();
    var partyName = $(indiLi).find("party").text();
    var party = $(xml).find("group[id='ppartyStats'] item").filter(":contains('"+partyName+"')");
    var partyRanking = Math.round(parseFloat($(party).find("avgRanking").text()));

    var manWomenName = $(indiLi).find("sex").text();
    var manWomen = $(xml).find("group[id='sexStats'] item").filter(":contains('"+manWomenName+"')");
    var manWomenRanking = Math.round(parseFloat($(manWomen).find("avgRanking").text()));

    var mayorName = $(indiLi).find("mayor").text();
    var mayor = $(xml).find("group[id='mayorStats'] item").filter(":contains('"+mayorName+"')");
    var mayorRanking = Math.round(parseFloat($(mayor).find("avgRanking").text()));

    var max = 0;
    $(xml).find("li").each(function() {
        var value = parseInt($(this).attr("ranking"));
        if (value > max) max = value;
    });

  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['', indiName, partyName, (manWomenName == 'M'? 'Mannen' : 'Vrouwen'), (mayorName == 'FALSE'? 'Niet-burgemeesters' : 'Burgemeesters')],
    ['', max - indiRanking, max - partyRanking, max - manWomenRanking, max - mayorRanking]
  ]);

  // Create and draw the visualization.
  new google.visualization.ColumnChart(document.getElementById(id)).
      draw(data,
           {title:"Ranking",
            tooltip: null,
            vAxis: {textPosition: 'none'},
            enableInteractivity: false}
      );
}

function activity_loadPartyQuartilePieChart(xml, container, partyName, showName) {
    partyName = partyName.replace('&amp;', '&');

    var list = [['kwartielen', 'aantal personen'],
                ['1e', null],
                ['2e', null],
                ['3e', null],
                ['4e', null]];

    $(xml).find("#ppartyStats item").each(function() {
        if ($(this).find("name").text() == partyName) {
            list[1][1] = parseInt($(this).find("firstPart").text());
            list[2][1] = parseInt($(this).find("secondPart").text());
            list[3][1] = parseInt($(this).find("thirdPart").text());
            list[4][1] = parseInt($(this).find("fourthPart").text());
        }
    });

    var data = google.visualization.arrayToDataTable(list);

    var options = {
        title: (showName? partyName : "Verdeling over de kwartielen"),
        is3D: true,
        colors: ['#ffff00', '#ffd300', '#ff5400', '#ff0000']
    };

    var chart = new google.visualization.PieChart(document.getElementById(container));
    chart.draw(data, options);
}

function activity_loadManWomenQuartilePieChart(xml, container, sex, showName) {
    var list = [['kwartielen', 'aantal personen'],
                ['1e', null],
                ['2e', null],
                ['3e', null],
                ['4e', null]];

    $(xml).find("#sexStats item").each(function() {
        if ($(this).find("name").text() == sex) {
            list[1][1] = parseInt($(this).find("firstPart").text());
            list[2][1] = parseInt($(this).find("secondPart").text());
            list[3][1] = parseInt($(this).find("thirdPart").text());
            list[4][1] = parseInt($(this).find("fourthPart").text());
        }
    });

    var data = google.visualization.arrayToDataTable(list);

    var options = {
        title: (showName? (sex == 'M'? 'Mannen' : 'Vrouwen') : "Verdeling over de kwartielen"),
        is3D: true,
        colors: ['#ffff00', '#ffd300', '#ff5400', '#ff0000']
    };

    var chart = new google.visualization.PieChart(document.getElementById(container));
    chart.draw(data, options);
}

function activity_loadMayorQuartilePieChart(xml, container, mayor, showName) {
    var list = [['kwartielen', 'aantal personen'],
                ['1e', null],
                ['2e', null],
                ['3e', null],
                ['4e', null]];

    $(xml).find("#mayorStats item").each(function() {
        if ($(this).find("name").text() == mayor) {
            list[1][1] = parseInt($(this).find("firstPart").text());
            list[2][1] = parseInt($(this).find("secondPart").text());
            list[3][1] = parseInt($(this).find("thirdPart").text());
            list[4][1] = parseInt($(this).find("fourthPart").text());
        }
    });

    var data = google.visualization.arrayToDataTable(list);

    var options = {
        title: (showName?  (mayor == 'TRUE'? 'Burgemeesters' : 'Niet-burgemeesters') : "Verdeling over de kwartielen"),
        is3D: true,
        colors: ['#ffff00', '#ffd300', '#ff5400', '#ff0000']
    };

    var chart = new google.visualization.PieChart(document.getElementById(container));
    chart.draw(data, options);
}

/* Colors and labels */

function activity_politicalPartyColors() {
    var colorList = new Array();
    colorList["N-VA"] = "ffac12";
    colorList["Open VLD"] = "003d6d";
    colorList["sp.a"] = "e23a3f";
    colorList["Groen"] = "83de62";
    colorList["LDD"] = "67c3e8";
    colorList["CD&V"] = "f5822a";
    colorList["Vlaams Belang"] = "ffe500";
    colorList["UF"] = "dcdcdc";
    colorList["Onafhankelijke"] = "787878";
    return colorList;
}

function activity_sexColors() {
    var colorList = new Array();
    colorList["M"] = "000080";
    colorList["F"] = "800000";
    return colorList;
}

function activity_sexLabels() {
    var colorList = new Array();
    colorList["M"] = "Mannen";
    colorList["F"] = "Vrouwen";
    return colorList;
}

function activity_mayorColors() {
    var colorList = new Array();
    colorList["FALSE"] = "000080";
    colorList["TRUE"] = "800000";
    return colorList;
}

function activity_mayorLabels() {
    var colorList = new Array();
    colorList["FALSE"] = "Niet-burgemeester";
    colorList["TRUE"] = "Burgemeester";
    return colorList;
}

function activity_fillRankingList(xml, id, showActivity) {
    // clear old lists
    $("#"+id).empty();


    var totalCost = 0;
    var lastValue = 0;
    var lastElement = null;

    $(xml).find("li").each(function(index) {
        var value = ($(this).find("value").text()*1);
        if (lastValue != value) {
            lastElement = ($("#"+id).append("<li><a href=\"individual.xql?id="+$(this).attr('ref')+"\" class=\""+$(this).find("role").text()+"\">"+$(this).find("name").text()+(showActivity? " ("+Math.round($(this).find("value").text())+"%)" : "") + "</a></li>"));
            lastValue = value;
        } else {
            $("#"+id+" li:last").append("<a href=\"individual.xql?id="+$(this).attr('ref')+"\" class=\""+$(this).find("role").text()+"\">"+$(this).find("name").text()+(showActivity? " ("+Math.round($(this).find("value").text())+"%)" : "") + "</a>");
        }

        totalCost += ($(this).find("value").text()*1);

        //index + ': ' + $(this, "name").text();
    });
}

function activity_fillTopList(xml, id, id2, id3) {
    // clear old lists
    $("#"+id2).empty();
    $("#"+id3).empty();

    var numberOfIndividuals = 0;
    var i = 0;
    var least = $("#"+id+" li").length-5;
    $("#"+id+" li").each(function(index) {
        if (i < 5) {
            $("#"+id2).append($(this).clone());
            }
        if (i >= least)
            $("#"+id3).prepend($(this).clone())
        ++i;
    });
    numberOfIndividuals = i;
}

function activity_drawValueChart(xml, itemId, colorList, containerPath, chartTitle, labelList, width, height) {
    var minAvgMaxList = ["minValue", "avgValue", "maxValue"];
    activity_drawChart(xml, itemId, colorList, containerPath, chartTitle, labelList, minAvgMaxList, false, width, height);
}

function activity_drawRankingChart(xml, itemId, colorList, containerPath, chartTitle, labelList, width, height) {
    var minAvgMaxList = ["minRanking", "avgRanking", "maxRanking"];
    activity_drawChart(xml, itemId, colorList, containerPath, chartTitle, labelList, minAvgMaxList, true, width, height);
}

function activity_drawChart(xml, itemId, colorList, containerPath, chartTitle, labelList, minAvgMaxList, rankingBased, width, height) {
    var max = 0;
    if (rankingBased) {
        $(xml).find("li").each( function() {
            var value = parseInt($(this).attr("ranking"));
            if (value > max) max = value;
        });
    } else max = 100;
    var itemList = new Array();
    var pathList = new Array();
    $(xml).find(itemId+" item").each(function(index) {
        var str = $(this).find("name").text();
        itemList[index] = str;
        pathList[index] = itemId+" item:nth-child(" + (index+1) + ")";
    });

    // iterate through list
    var minMidMaxData = "";
    for (j =0; j<minAvgMaxList.length; ++j) {
        if (j!=0) minMidMaxData += "|";
        for (i=0; i<pathList.length; ++i) {
            if (i!=0)
                minMidMaxData += ","; 
            var value = $(xml).find(pathList[i] + " " + minAvgMaxList[j]).text();
            if (rankingBased)
                minMidMaxData += (value == "" || value == 0? 0 : max - (value == ""? 0 : value));
            else
                minMidMaxData += (value == ""? 0 : value);
        }
    }

    // iterate through list
    var labelData = "";
    for (i =0; i<itemList.length; ++i) {
        if (i!=0) labelData += "|";
        labelData += labelList != null? labelList[itemList[i]] : itemList[i];
    }
    labelData = labelData.replace("&", "%26");

    if (rankingBased) {
        // create colors
        var colorData = "";
        for (j=0; j<2; ++j) {
            if (j != 0)
                colorData += ",";
            for (i=0; i<itemList.length; ++i) {
                if (i!=0)
                    colorData += "|";
                colorData += colorList[itemList[i]] + (j==1? "" : "33");
            }
        }
        colorData += ",00000055";
    } else {
        // create colors
        var colorData = "00000055";
        for (j=0; j<2; ++j) {
            colorData += ",";
            for (i=0; i<itemList.length; ++i) {
                if (i!=0)
                    colorData += "|";
                colorData += colorList[itemList[i]] + (j==1? "33" : "");
            }
        }
    }

    var container = $(containerPath).html('<img width="'+width+'" height="'+height+'" alt="'+chartTitle+'" src="http://chart.apis.google.com/chart?chxt=y&chds=0,'+max+'&chxr=0,0,'+max+'&chbh=a,200,200&chs='+width+'x'+height+'&cht=bvo&chl='+labelData+'&chco='+colorData+'&chd=t:'+minMidMaxData+'" />');
}

//$(this, "firstPart").text(), $(this, "secondPart"), $(this, "thirdPart"), $(this, "fourthPart").text()

function drawChart(chartId, firstPart, secondPart, thirdPart, fourthPart, title) {
    //alert(firstPart + " : " + secondPart + " : " + thirdPart + " : " + fourthPart);
        var data = google.visualization.arrayToDataTable([
          ['Kwartiel', 'Aantal personen'],
          ['1 (top)',     firstPart],
          ['2',      secondPart],
          ['3',  thirdPart],
          ['4', fourthPart],
        ]);

        var options = {
          title: title,
          is3D: true
        };

        var chart = new google.visualization.PieChart(document.getElementById(chartId));
        chart.draw(data, options);
}

function drawPartChart(chartId, list, title, colorList) {
        var data = google.visualization.arrayToDataTable(list);

        var options = {
          title: title,
          is3D: true,
          colors: colorList
        };

        var chart = new google.visualization.PieChart(document.getElementById(chartId));
        chart.draw(data, options);
}

function drawIndividualPartChart(chartId, list, title, colorList) {
        var data = google.visualization.arrayToDataTable(list);

        var options = {
          title: title,
          is3D: true,
          colors: colorList,
          legend: {position: 'none'}
        };

        var chart = new google.visualization.PieChart(document.getElementById(chartId));
        chart.draw(data, options);
}


function activity_loadIndividualAnnualRanking(mainXML, valueID, rankingID, individualID) {
    var totalRanking = parseInt($(mainXML).find('root li[ref=\''+individualID+'\']').attr('ranking'));
    var totalMaxRanking = parseInt($(mainXML).find('maxIndiRanking').text());
    var totalValue = parseInt($(mainXML).find('root li[ref=\''+individualID+'\'] value').text());


        $.ajax({
            url: "activity_progress.xql"
            + "?present="+(weights['present'] / 100)+"&initiator="+(weights['initiatives'] / 100)
            + "&participation="+(weights['participation'] / 100)
            + "&interuption="+(weights['interuption'] / 100)
            + "&wordCount="+(weights['wordCount'] / 100)
            + "&initiatedParticipation="+(weights['initiatedParticipation'] / 100)
            + "&includeChair="+checkBox['chair']
            + "&includeGovernment="+checkBox['government']
            + "&includeMP="+checkBox['mp']
            + "&id="+individualID,
            dataType: "xml",
            success: function(xml) {
                var vData = new google.visualization.DataTable();
                vData.addColumn('string', 'Periode');
                vData.addColumn('number', 'Graad');
                vData.addColumn({type:'string',role:'tooltip'});
                vData.addColumn('number', 'Algemene graad');
                vData.addColumn({type:'string', role:'tooltip'});
                vData.addColumn('number', 'Gemiddelde');
                vData.addColumn({type:'string',role:'tooltip'});

                var rData = new google.visualization.DataTable();
                rData.addColumn('string', 'Periode');
                rData.addColumn('number', 'Ranking');
                rData.addColumn({type:'string',role:'tooltip'});
                rData.addColumn('number', 'Totale ranking');
                rData.addColumn({type:'string', role:'tooltip'});
                rData.addColumn('number', 'Gemiddelde');
                rData.addColumn({type:'string',role:'tooltip'});

                var i = 0;
                $(xml).find('period').each(function() {
                    var label = $(this).find("label").text();
                    var value = parseInt($(this).find("value").text());
                    var ranking = parseInt($(this).find("ranking").text());
                    var maxRanking = parseInt($(this).find("max").text());
                    var avgValue = parseInt($(this).find("avgValue").text());
                    var avgRanking = parseInt($(this).find("avgRanking").text());
                    vData.addRow();
                    vData.setValue(i, 0, label);
                    vData.setValue(i, 1, value);
                    vData.setValue(i, 2, 'activiteitsgraad: ' + value + "%");
                    vData.setValue(i, 3, totalValue);
                    vData.setValue(i, 4, 'Totale activiteitsgraad: ' + totalValue + "%");
                    vData.setValue(i, 5, avgValue);
                    vData.setValue(i, 6, 'gemiddelde activiteitsgraad: ' + avgValue + "%");

                    rData.addRow();
                    rData.setValue(i, 0, label);
                    rData.setValue(i, 1, (avgRanking == 1? null : maxRanking - ranking));
                    rData.setValue(i, 2, 'Ranking: ' + ranking);
                    rData.setValue(i, 3, totalMaxRanking - totalRanking);
                    rData.setValue(i, 4, 'Totale ranking: ' + totalRanking);
                    rData.setValue(i, 5, (avgRanking == 1? null : avgRanking));
                    rData.setValue(i, 6, 'gemiddelde ranking: ' + avgRanking);

                    ++i;
                });

            var chart = new google.visualization.LineChart(document.getElementById(valueID));
            chart.draw(vData, {title : 'Activiteitsgraad', colors : ['red', 'blue', 'gray']});

            var chart2 = new google.visualization.LineChart(document.getElementById(rankingID));
            chart2.draw(rData, {title : 'Ranking', colors : ['red', 'blue', 'gray']});

            }
        });
}

